package com.sunny.design.observer.jdk;

import java.util.Observable;
import java.util.Observer;

/**
 * JDK提供的观察者实现方式
 *
 * @author Sunny
 * @date 2020/1/15
 */
public class Teacher implements Observer {

    private String name;

    public Teacher(String name) {
        this.name = name;
    }

    /**
     * 当被观察者的状态发生变化后，观察者就会收到消息进行处理
     *
     * @param o
     * @param arg
     */
    @Override
    public void update(Observable o, Object arg) {
        BaiDu baidu = (BaiDu) o;
        Question question = (Question) arg;

        System.out.println("=============" + baidu.getName() + "==================");
        System.out.println(getName() + "老师您好，您收到了一个来自：" + question.getUserName() + "的提问！请您解答！问题内容如下：");
        System.out.println(question.getContent());
    }

    public String getName() {
        return name;
    }
}
